package org.zjt.platform.demo.config;

import org.zjt.platform.demo.config.properties.WebProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * 功能描述:Swagger与springboot集成配置类
 *
 * @author sunchangji
 * @date 2016/11/14
 */
@Configuration
@EnableSwagger2
@EnableConfigurationProperties(WebProperties.class)
public class SwaggerConfiguration {




	@Bean
	public Docket createRestApi(WebProperties webProperties) {
		return new Docket(DocumentationType.SWAGGER_2)
				.enable(webProperties.getSwaggerEnable())
				.apiInfo(apiInfo(webProperties))
				.select()
				.apis(RequestHandlerSelectors.basePackage(webProperties.getSwaggerBasePackage()))
				.paths(PathSelectors.any())
				.build();
	}

	private ApiInfo apiInfo(WebProperties webProperties) {
		return new ApiInfoBuilder()
				.title(webProperties.getTitle())
				.description(webProperties.getDescription())
				.termsOfServiceUrl("")
				.contact(webProperties.getContact())
				.version(webProperties.getVersion())
				.build();
	}
}
